<template>
  <d-dialog
    ref="dialog"
    :header="formData.isEdit ? '编辑字典' : '新增字典'"
    api="system/dict/type"
    v-model:data="formData"
    v-model:visible="visible"
    :rules="rules"
  >
    <t-form-item label="字典名称" name="dictName">
      <t-input v-model="formData.dictName" placeholder="请输入字典名称"></t-input>
    </t-form-item>
    <t-form-item label="字典类型" name="dictType">
      <t-input v-model="formData.dictType" placeholder="请输入字典类型"></t-input>
    </t-form-item>
    <t-form-item label="状态" name="status">
      <t-radio-group v-model="formData.status" :options="dict.dict_enable_list" />
    </t-form-item>
    <t-form-item label="备注">
      <t-textarea v-model="formData.remark" placeholder="请输入备注内容" />
    </t-form-item>
  </d-dialog>
</template>

<script setup>
import { merge } from '@common'
import { useDict } from '@/store/dict'
import { ref } from 'vue'
const INIT_STATUS = {
  dictId: '',
  dictName: '',
  dictType: '',
  status: '0',
  remark: ''
}
const dict = useDict()
const dialog = ref(null)
const visible = ref(false)
const formData = ref({ ...INIT_STATUS })
const rules = {
  dictName: [{ required: true, message: '请输入字典名称', trigger: 'blur' }],
  dictType: [{ required: true, message: '请输入字典类型', trigger: 'blur' }]
}
const show = async (info = {}) => {
  const obj = merge({ ...INIT_STATUS, isEdit: !!info.dictId }, info)
  formData.value = obj
  visible.value = true
}
defineExpose({ show })
</script>
